﻿using EMoney.IStock.Client.Models.Cpyx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EMoney.IStock.Client.DataAccess.Cpyx
{
    /// <summary>
    /// 连续参加K线英雄游戏数据访问类
    /// </summary>
    public class KContinueGameDal
    {
        /// <summary>
        /// 新增连续参加K线英雄游戏信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int AddKContinueGame(KContinueGame obj)
        {
            string sql = "insert into K_ContinueGame(UserID,GameDays,GameDate,UpdateTime) values(@UserID,@GameDays,@GameDate,getdate())";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("UserID", System.Data.SqlDbType.Int, obj.UserID);
            tools.AddSqlParameter("GameDays", System.Data.SqlDbType.Int, obj.GameDays);
            tools.AddSqlParameter("GameDate", System.Data.SqlDbType.DateTime, obj.GameDate);

            return SQLHelper.ExecuteNonQuery(ConnectionManager.Emfstock, System.Data.CommandType.Text, sql, tools.GetSqlParameters());
        }

        /// <summary>
        /// 修改连续参加K线英雄游戏信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int UpdateKContinueGame(KContinueGame obj)
        {
            string sql = "update K_ContinueGame set GameDays=@GameDays,GameDate=@GameDate,UpdateTime=getdate() where UserID=@UserID";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("UserID", System.Data.SqlDbType.Int, obj.UserID);
            tools.AddSqlParameter("GameDays", System.Data.SqlDbType.Int, obj.GameDays);
            tools.AddSqlParameter("GameDate", System.Data.SqlDbType.DateTime, obj.GameDate);

            return SQLHelper.ExecuteNonQuery(ConnectionManager.Emfstock, System.Data.CommandType.Text, sql, tools.GetSqlParameters());
        }

        /// <summary>
        /// 获取连续参加K线英雄游戏信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public KContinueGame GetKContinueGame(int userid)
        {
            string sql = "select top 1 * from K_ContinueGame where UserID=@UserID order by UpdateTime desc";

            SQLTools tools = new SQLTools();

            tools.AddSqlParameter("UserID", System.Data.SqlDbType.Int, userid);

            return SQLHelper.GetDataByColumns<KContinueGame>(ConnectionManager.Emfstock, sql, tools.GetSqlParameters());
        }
    }
}
